﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using Asd.MP.Entity;
using Asd.MP.Utility;

namespace MobilePlatform.Controllers
{
    public class InfoCenterController : BaseController
    {
        private string _account = "leo.dong";

        public ActionResult MobileList()
        {

            return View(_systemInfoBal.GetSerailNoListByAccount(_account));
        }

        [HttpPost]
        public ActionResult RegisterMobile(string mobile)
        {

            mobile = mobile.Trim();
            MessageHelper msg = new MessageHelper(MessageStatus.Error);
            msg.Required(mobile, "手机号码不能为空");

            if (msg.IsValid)
            {
                if (_systemInfoBal.SaveSerail(mobile, _account) != 1)
                {
                    msg.AddBody(MessageStatus.Error, "手机号码已经被注册", "手机号码已经被注册");
                    msg.AddMessage("这个手机号码已经被注册,你不能使用改手机号码");
                }
                else
                {
                    msg.AddBody(MessageStatus.Ok, "恭喜你,注册手机号码成功", "恭喜你,注册手机号码成功");
                    msg.AddMessage("恭喜你,注册手机号码成功");
                    msg.DefaultOperate(Url.Action("MobileList"));
                }
            }
            return MessageResult(msg.CreateMessage());
        }

        public ActionResult ModifyMobile(string sn = "")
        {
            MessageHelper msg = new MessageHelper(MessageStatus.Error);
            msg.AddBody("处理请求时发送错误");
            msg.Required(sn, "非法请求");

            List<SerialNoEntity> serialList = new List<SerialNoEntity>();
            serialList.Add(new SerialNoEntity()
            {
                EMPAccount = _account,
                Sn = sn,
                Status = (int)SerialNoStatus.Locked
            });

            if (msg.IsValid)
            {
                _systemInfoBal.ModifySerialNoStatus(serialList);
                msg.AddBody(MessageStatus.Ok, "恭喜你,操作成功", "你的操作已经成功,但是你的账号已经被锁定,请耐心等待管理员审核");
                msg.DefaultOperate(Url.Action("MobileList"));

            }
            return MessageResult(msg.CreateMessage());
        }


        public ActionResult PlatformDownload(string veryCode)
        {
            return Content(veryCode);
        }
    }
}
